<template>
  <el-card class="box-card">
    <el-form :model="editForm" label-width="100px"  ref="editForm">
      <el-form-item label="收货人姓名" prop="receiverName" :rules="{required: true, message: '请输入收货人姓名', trigger: 'blur'}">
        <el-input v-model="editForm.receiverName" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="receiverPhone" :rules="[{required: true, message: '请输入联系方式', trigger: 'blur'}]">
        <el-input v-model="editForm.receiverPhone"></el-input>
      </el-form-item>
      <el-form-item label="收货地址" prop="receiverAddress" :rules="[{required: true, message: '请输入收货地址', trigger: 'blur'}]">
        <el-input v-model="editForm.receiverAddress"></el-input>
      </el-form-item>
    </el-form>
    <el-button @click="update()">更新配送单</el-button>
    <el-button @click="back()">返回</el-button>
  </el-card>
</template>
<style>
</style>
<script>
export default{
  created() {
     this.loadGridData();
  },
  data(){
     return{
        editForm:{
           receiverName:'',
           receiverPhone:'',
           receiverAddress:''
        },
     }
  },
  methods:{
     loadGridData() {
        let orderId=this.$route.params.orderId;
			  this.axios.get(`shipments/${orderId}`).then(response=>{
			    this.editForm=response.data})
     },
     back(){
        let orderId=this.$route.params.orderId;
        this.$router.push(`/shipments/${orderId}`);
     },
     update(){
        let orderId=this.$route.params.orderId
        this.$refs.editForm.validate((valid) => {
					 if (!valid) {
						 return
					  }
				  this.$confirm('确认提交吗？','提示',{
				    cancelButtonText: '取消',
            confirmButtonText: '确定',
				  }).then(() => {
            this.axios.patch(`shipments/${orderId}`,this.editForm).then(()=>{
              this.$notify({
                title: '成功',
                message: '提交成功',
                type: 'success'
               })
            }).then(()=>{
                  this.back()
                })
          })
        })
     }
  }
}
</script>
